# Copyright (C) Nicola Bizzoca   2006/2007  <hannibal_smith@users.sourceforge.net>
# Copyright (C) Simone Economo   2006/2007  <ekoes@users.sourceforge.net>
# 
#    This file is part of Absynth-FTP.
#
#    Absynth-FTP is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    Absynth-FTP is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gtk, TreeViewNew, PopupMenuNew, TextView, ToolBar, NoteBook


class testSuite:
    
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.__createFramework()
        
        self.window.show_all()
        
        self.connectEvents({
             "delete_event" : self.delete,
             "destroy": self.destroy,
        })
        
    def __createFramework(self):
        vbox, menubar, toolbar, hbox, textview, statusbar = \
            gtk.VBox(), \
            self.__createMenuBar(), \
            self.__createToolBar(), \
            self.__createHBox(), \
            self.__createTextView(), \
            gtk.Statusbar()
        vbox.pack_start(menubar.widget, False, False)
        vbox.pack_start(toolbar.widget, False, False)
        vbox.pack_start(hbox, padding = 5)
        vbox.pack_start(textview, False, padding = 5)
        vbox.pack_start(statusbar, False, False)
        self.window.add(vbox)
        self.window.set_default_size(800, 600)
        
    def __createMenuBar(self):
        #menubar = gtk.MenuBar()
        #menubar.set_size_request(-1, 24)
        fileitem = PopupMenuNew.genericPopupMenu()
        fileitem.addSimpleEntry("Nuovo", "Crea nuovo file", gtk.STOCK_NEW, "<control>N", "N")
        fileitem.addSimpleEntry("Apri", "Apri file esistente", gtk.STOCK_OPEN, "<control>O", "O")
        fileitem.addSimpleEntry("Salva", "Salva file", gtk.STOCK_SAVE, "<control>S", "S")
        fileitem.addSeparatorEntry()
        fileitem.addSimpleEntry("Esci", "Rimuovi file", gtk.STOCK_QUIT, "<control>Q", "Q")
        menubar = PopupMenuNew.genericMenuBar()
        menubar.addMenuEntry("File","F", fileitem)
        #print menubar.getByName("File")
        return menubar
    
    def __createToolBar(self):
        toolbar = ToolBar.genericToolBar({
            "orientation": "hor",
            "tooltips"   : True,
            "layout"     : "both",
        })
        toolbar.addImageButton(gtk.STOCK_NETWORK, "Wizard")
        toolbar.addItem(gtk.VSeparator())
        toolbar.addToggleButton(gtk.STOCK_CONNECT)
        #toolbar.set_size_request(-1, 60)
        return toolbar
    
    def __createHBox(self):
        hbox = gtk.HBox()
        
        localtree = TreeViewNew.genericListView({
            "headers-visible"  : True,
            "headers-clickable": True,
            "rows-search"      : True,
            "rows-same-height" : False,
            "rows-alternate"   : True,
            "rows-reorder"     : False,
        })
        
        localtree.addImageColumn("Filename", True, True)
        localtree.addTextColumn("-", str, False, False)
        localtree.addTextColumn("Size", str, True, False, 50)
        localtree.addTextColumn("Last Edit", str, True, True)
        localtree.mergeColumns(0, 1, None, None)
        
        localtree.addRow(["stock_folder", "usr", "4096", "aee"])
        localtree.addRow(["stock_folder", "bin", "4096", "?"])
        localtree.addRow(["stock_folder", "etc", "4096", "?"])
        localtree.addRow(["stock_folder", "var", "4096", "?"])
        localtree.addRow(["stock_folder", "local", "4096", "?"], position = 1)
        
        remotetree = TreeViewNew.genericListView({
            "headers-visible"  : True,
            "headers-clickable": True,
            "rows-search"      : True,
            "rows-same-height" : False,
            "rows-alternate"   : True,
            "rows-reorder"     : False,
        })
        
        remotetree.addImageColumn("Filename", True, True)
        remotetree.addTextColumn("-", str, False, False)
        remotetree.addTextColumn("Size", str, True, False, 50)
        remotetree.addTextColumn("Last Edit", str, True, True)
        remotetree.mergeColumns(0, 1, None, None)
        
        remotetree.addRow(["stock_folder", "usr2", "4096", "aee"])
        remotetree.addRow(["stock_folder", "bin2", "4096", "?"])
        remotetree.addRow(["stock_folder", "etc2", "4096", "?"])
        remotetree.addRow(["stock_folder", "var2", "4096", "?"])
        remotetree.addRow(["stock_folder", "local2", "4096", "?"], position = 1)
        
        localbook = NoteBook.genericNoteBook({
            "show-border"  : False,
            "show-tabs"    : True,
            "show-arrows"  : True,
            "tabs-reorder" : True,
            "group-name"   : "connection",
            "tabs-detach"  : True,
            "tabs-position": "top",
        })
        localbook.addPage(gtk.STOCK_DIRECTORY, "Local 1", localtree.widget, None, True)
    
        remotebook = NoteBook.genericNoteBook({
            "show-border"  : False,
            "show-tabs"    : True,
            "show-arrows"  : True,
            "tabs-reorder" : True,
            "group-name"   : "connection",
            "tabs-detach"  : True,
            "tabs-position": "top",
        })
        remotebook.addPage(gtk.STOCK_DISCONNECT, "Remote 1", remotetree.widget, None, True)

        hbox.pack_start(localbook.widget, padding = 5)
        hbox.pack_start(remotebook.widget, padding = 5)
        return hbox
    
    def __createTextView(self):
        
        downloadtree = TreeViewNew.genericTreeView({
            "headers-visible"  : True,
            "headers-clickable": True,
            "rows-search"      : True,
            "rows-same-height" : False,
            "rows-alternate"   : True,
            "rows-reorder"     : False,
        })
        
        downloadtree.addImageColumn("Filename", True, True)
        downloadtree.addTextColumn("-", str, False, False)
        downloadtree.addProgressColumn("Progress", True, True)
        downloadtree.mergeColumns(0, 1, None, None)
        downloadtree.columns[0].rend.set_property('xalign', 0.0)
        downloadtree.columns[0].col.set_sort_column_id(1)
        
        downloadtree.addRow(["stock_folder", "ftp.something.not", 0])
        downloadtree.addRow(["stock_folder", "usr", 0], parent = 0)
        downloadtree.addRow(["stock_folder", "bin", 0], parent = 0)
        downloadtree.addRow(["stock_folder", "etc", 0], parent = 0)
        downloadtree.addRow(["stock_folder", "var", 0], parent = 0)
        downloadtree.addRow(["stock_folder", "local", 0], parent = 0)
        
        uploadtree = TreeViewNew.genericTreeView({
            "headers-visible"  : True,
            "headers-clickable": True,
            "rows-search"      : True,
            "rows-same-height" : False,
            "rows-alternate"   : True,
            "rows-reorder"     : False,
        })
        
        uploadtree.addImageColumn("Filename", True, True)
        uploadtree.addTextColumn("-", str, False, False)
        uploadtree.addProgressColumn("Progress", True, False)
        uploadtree.mergeColumns(0, 1, None, None)
        uploadtree.columns[0].rend.set_property('xalign', 0.0)
        uploadtree.columns[0].col.set_sort_column_id(1)
        
        uploadtree.addRow(["stock_folder", "ftp2.something.not", 0])
        uploadtree.addRow(["stock_folder", "usr2", 0], parent = 0)
        uploadtree.addRow(["stock_folder", "bin2", 0], parent = 0)
        uploadtree.addRow(["stock_folder", "etc2", 0], parent = 0)
        uploadtree.addRow(["stock_folder", "var2", 0], parent = 0)
        uploadtree.addRow(["stock_folder", "local2", 0], parent = 0)
        
        textview = TextView.genericTextView({
            "editable"    : False,
            "cursor-blink": False,
            "wrap-mode"   : "word",
            "align-mode"  : "left",
        })
        textview.setScrollbar()
        textview.scrollbar.set_size_request(-1, 180)
        textview.setMargin(10, 5)
        textview.writeTextLines([chr(numb) for numb in range(33, 100)])
        
        textbook = NoteBook.genericNoteBook({
            "show-border"  : False,
            "show-tabs"    : True,
            "show-arrows"  : True,
            "tabs-reorder" : True,
            "tabs-detach"  : False,
            "tabs-position": "top",
        })
        textbook.addPage(None, "Logs", textview.scrollbar, None, False)
        textbook.addPage(gtk.STOCK_GO_DOWN, "Downloads", downloadtree.widget, None, True)
        textbook.addPage(gtk.STOCK_GO_UP, "Uploads", uploadtree.widget, None, False)
        
        hbox = gtk.HBox()
        hbox.pack_start(textbook.widget, padding = 5)
        return hbox
    
    def connectEvents(self, events):
        for type,callback in events.items():
            self.window.connect(type, callback)

    def delete(self, widget, event, data=None):
        #print "delete event occurred"
        return False

    def destroy(self, widget, data=None):
        #print "destroy signal occurred"
        gtk.main_quit()
        
    def runTest(self):
        gtk.main()
        
if __name__ == "__main__": 
    GTK = testSuite()
    GTK.runTest()